{extend name="public/base" /}

{block name="title"}添加管理员{/block}

{block name="main"}
<div class="layui-tab" id="Js_title_navigation">
    <ul class="layui-tab-title">
        <li class="layui-this">添加管理员</li>
    </ul>
</div>
<form class="layui-form layui-row " action="" method="post">
    <input type="hidden" value="{$adminid}" name="adminid" />
	<div class="layui-col-xs12" style="padding-bottom: 50px;">
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">登录账户：</label>
            <div class="layui-input-block">
				<input type="text" name="account" lay-verify="required|username" required value="{$admin['account']}" placeholder="请输入用户名用于登录" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">设置密码：</label>
			<div class="layui-input-block">
				<input type="password" name="password" value="" placeholder="不修改密码,请留空" class="layui-input pwd">
			</div>
		</div>
		<div id="confirmPwd" style="display: none;" class="layui-form-item layui-col-md4">
			<label class="layui-form-label">确认密码：</label>
			<div class="layui-input-block">
				<input type="password" name="confirmPwd" value="" placeholder="请确认密码" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">姓名：</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="{$admin['name']}" placeholder="请输入姓名" lay-verify="required" class="layui-input pwd"/>
			</div>
		</div>
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">手机号：</label>
			<div class="layui-input-block">
				<input type="text" name="mobile" value="{$admin['mobile']}" placeholder="请输入手机号" class="layui-input pwd">
			</div>
		</div>
        <div class="layui-form-item layui-col-md4">
            <label class="layui-form-label">所属角色：</label>
            <div class="layui-input-inline">
              <select name="roleid">
                {volist name="roleList" id="v"}
                <option value="{$v['id']}" {$v['id']==$admin['roleid']?'selected':''} >{$v['role']}</option>
                {/volist}
              </select>
            </div>
        </div>
         
	</div>
    <div class="layui-layout-admin" >
        <div class="layui-footer" style="left:0;">
            <div class="layui-form-item">                
                <a href="javascript:;" class="layui-btn layui-btn-primary" onclick="javascript:history.back();">返回</a>
                <button type="reset" class="layui-btn layui-btn-normal">重置</button>
                <button type="button" class="layui-btn" lay-submit="" lay-filter="saveFrom">保存</button>
			</div>
        </div>
    </div>

</form>
{/block}
{block name="script"}
<script>
layui.use(['form','common'],function(){
    var form = layui.form;
        
    $("[name=password]").bind("input placeholder",function(){
        if($(this).val().length>0){
            $("#confirmPwd").show();
        }else{
            $("#confirmPwd").hide();
        }
    })
    
    form.on('submit(saveFrom)',function(data){
        if( data.field.password ){
            if(data.field.password.length<6){
                layer.msg("密码长度不能小于6",{icon:5});
                return false;
            }
            if(data.field.password!=data.field.confirmPwd){
                layer.msg("两次输入密码不一致",{icon: 5});
                return false;
            }
        }
        layui.common.post("/sys/account/edit",data.field);
        return false;
    });
    
    form.render(); //更新全部
})
</script>
{/block}